
#include "EquationSolver.hpp"

const double pi=acos(-1);

// implement the funciton of derived class function1.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function1:public Function{
public:
    double operator()(const double &x) const {
        return (sin(x/2.0)-1.0);
    }
    void sol1()
    {
        Secant solver1((*this),0.0,pi/2,_eps,1000);
        std::cout<<"(I) f(x)=sin(x/2)-1=0, x0=0, x1=pi/2. ";
        solver1.solve();
        std::cout<<std::endl;
    }
}f1;

// implement the funciton of derived class function2.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function2:public Function{
public:
    double operator()(const double &x) const {
        return (exp(x)-tan(x));
    }
    void sol2()
    {
        Secant solver2((*this),1.0,1.4,_eps,1000);
        std::cout<<"(II) f(x)=e^x-tanx=0, x0=1.0, x1=1.4. ";
        solver2.solve();
        std::cout<<std::endl;
    }
}f2;

// implement the funciton of derived class function3.
// The action is based on EquationSolver.h to solve the roots of special equation.
// example:
//    (Temporarily omitted.)
class Function3:public Function{
public:
    double operator()(const double &x) const {
        return (pow(x,3.0)-12*pow(x,2.0)+3*x+1);
    }
    void sol3()
    {
        Secant solver3((*this),0.0,-0.5,_eps,1000);
        std::cout<<"(III) f(x)=x^3-12x^2+3x+1=0, x0=0, x1=-0.5. ";
        solver3.solve();
        std::cout<<std::endl;
    }
}f3;

int main()
{
    std::cout<<"The Assignment D tests Secant method by several equations as follows."<<std::endl<<std::endl;
    f1.sol1();
    f2.sol2();
    f3.sol3();
    std::cout<<"--------------------Test succeeds.--------------------"<<std::endl<<std::endl;
    return 0;
}

